package com.CGFrame.struts.action;

import java.util.LinkedList;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.Globals;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.CGFrame.struts.bean.UserLogin.LoginBean;
import com.CGFrame.struts.bean.project.ProjectBean;
import com.CGFrame.struts.bean.reguser.ReguserBean;

public class ChangeLanAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		String lang=request.getParameter("lang");
		Locale newLocale=null;
		if(lang.equals("ch")){
			newLocale=new Locale("zh","CN");
		}
		if(lang.equals("en")){
			newLocale=new Locale("en","GB");
		}
		HttpSession session=request.getSession();
		if(newLocale!=null){
			session.setAttribute(Globals.LOCALE_KEY, newLocale);
		}
		ProjectBean pj=new ProjectBean((String)request.getSession().getAttribute("ProjectID"));
		String proName=pj.getProjectName();
		request.setAttribute("proName", proName);
		
		String regUserId = (String)session.getAttribute("RegUserID");
		ReguserBean rb=new ReguserBean(regUserId);
		request.setAttribute("ReguserName", rb.getReguserName());
		LoginBean lb = new LoginBean(regUserId);
		LinkedList lnlist=lb.getProjectIds();
		request.setAttribute("pros", lnlist);
		
		return mapping.findForward("main");
	}
	
}
